package com.atguigu.vod.controller;

import com.atguigu.annotation.WebLog;
import com.atguigu.commonutils.R;
import com.atguigu.vod.service.VodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/eduvod/video")
@CrossOrigin
public class VodController {

    @Autowired
    private VodService vodService;

    /**
     * 上传视频的方法
     * @return
     */
    @WebLog("上传视频")
    @PostMapping("/uploadAliyunVideo")
    public R uploadAliyunVideo(MultipartFile file) {
        // 返回上传视频的id
        String videoId = vodService.uploadAliyunVideo(file);
        return R.ok().data("videoId", videoId);
    }

    /**
     * 删除视频的方法
     * @return
     */
    @WebLog("删除单个视频")
    @DeleteMapping("/deleteAliyunVideo/{videoId}")
    public R deleteAliyunVideo(@PathVariable String videoId) {
        vodService.deleteAliyunVideo(videoId);
        return R.ok();
    }

    /**
     * 删除视频的方法
     * @return
     */
    @WebLog("删除多个视频")
    @DeleteMapping("/delete-batch")
    public R deleteBatchAliyunVideo(@RequestParam List<String> videoList) {
        vodService.deleteBatchAliyunVideo(videoList);
        return R.ok();
    }

    @WebLog("根据视频id获取播放凭证")
    @GetMapping("getVideoPlayAuthById")
    public R getVideoPlayAuthById(@RequestParam String vodeoId) {
        String videoPlayAuth = vodService.getVideoPlayAuthById(vodeoId);
        return R.ok().data("videoPlayAuth", videoPlayAuth);
    }

}
